CMAKE_MINIMUM_REQUIRED(VERSION 3.10)

LIST( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake )

SET_TARGET_PROPERTIES ( ${PROJECT_EXECUTABLES} PROPERTIES
  LINKER_LANGUAGE CXX
  )


FIND_PACKAGE (Lua 5.1 REQUIRED)

INCLUDE_DIRECTORIES (
  ${CMAKE_SOURCE_DIR}/include/
  ${CMAKE_BINARY_DIR}/include/
  ${LUA_INCLUDE_DIR}
  )

SET ( LUAMODEL_CASADI_SOURCES
  ${CMAKE_SOURCE_DIR}/addons/luamodel/luamodel.cc
  ${CMAKE_SOURCE_DIR}/addons/luamodel/luatables.cc
)

IF (RBDL_BUILD_STATIC)
  ADD_LIBRARY ( rbdl_luamodel-casadi-static STATIC ${LUAMODEL_CASADI_SOURCES} )
  TARGET_INCLUDE_DIRECTORIES( rbdl_luamodel-casadi-static PUBLIC
    ${CMAKE_SOURCE_DIR}/include/
    ${RBDL_CASADI_INCLUDE_DIR}
    ${LUA_INCLUDE_DIR}
  )
  IF (NOT WIN32)
    SET_TARGET_PROPERTIES ( rbdl_luamodel-casadi-static PROPERTIES PREFIX "lib")
  ENDIF (NOT WIN32)
  SET_TARGET_PROPERTIES ( rbdl_luamodel-casadi-static PROPERTIES OUTPUT_NAME "rbdl_luamodel-casadi")

  TARGET_LINK_LIBRARIES (rbdl_luamodel-casadi-static
    rbdl-casadi-static
    ${LUA_LIBRARIES}
  )

  INSTALL (TARGETS rbdl_luamodel-casadi-static
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  )

ELSE (RBDL_BUILD_STATIC)
  ADD_LIBRARY ( rbdl_luamodel-casadi SHARED ${LUAMODEL_CASADI_SOURCES} )
  TARGET_INCLUDE_DIRECTORIES( rbdl_luamodel-casadi PUBLIC
    ${CMAKE_SOURCE_DIR}/include/
    ${RBDL_CASADI_INCLUDE_DIR}
    ${LUA_INCLUDE_DIR}
  )
  SET_TARGET_PROPERTIES ( rbdl_luamodel-casadi PROPERTIES
    VERSION ${RBDL_VERSION}
    SOVERSION ${RBDL_SO_VERSION}
    )

  TARGET_LINK_LIBRARIES (rbdl_luamodel-casadi
    rbdl-casadi
    ${LUA_LIBRARIES}
  )

  INSTALL (TARGETS rbdl_luamodel-casadi
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    )

ENDIF (RBDL_BUILD_STATIC)

FILE ( GLOB headers
  "${CMAKE_SOURCE_DIR}/addons/luamodel/*.h"
  )

INSTALL ( FILES ${headers}
  DESTINATION
  ${CMAKE_INSTALL_INCLUDEDIR}/rbdl-casadi/rbdl/addons/luamodel
  )
